package com.picturehistory.core.jersey.resources;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.picturehistory.core.jersey.model.Employee;
import com.picturehistory.core.jersey.services.EmployeeService;


@Path("/employee")
@Component
public class EmployeeResource {

	@Autowired
	private EmployeeService service;
		
	public EmployeeResource() {}
	
	@GET
	@Produces("text/plain")
	public String getHello() {
		return "Hello world";
	}
	
	@POST
	@Path("/{title}/{first}/{last}")
	@Produces("text/plain")
	public String addEmployee(@Context UriInfo uri, @PathParam("title") String title, 
			@PathParam("first") String first, @PathParam("last") String last) {
		
		service.store(title, first, last);
		
		return title + " " + first + " " + last;
	}
	
	@GET
	@Path("/{first}/{last}")
	@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
	public Employee getEmployee(@Context UriInfo uri, @PathParam("first") String first,
			@PathParam("last") String last) {
		
		Employee e = service.load(first, last);
		return e;
	}
	
}

